import axios from 'axios';

const service = axios.create({
    baseURL: '/api',
    timeout: 5000
});

service.interceptors.request.use(
    config => {
        config.headers['Authorization'] = getToken();
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

function getToken() {
    return "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIiwiaWF0IjoxNzY0MzI2MzAzLCJleHAiOjE3NjQzNDA3MDMsInRva2VuIjoiZjE0Mjc3Y2QtNTJjOS00N2NhLWI2YWUtZjRiYTMzNTFkNjRlIn0.4tcHGx6r73unCQZokbNtGBCa-KdREo12jWF7PFud6os";
    //return localStorage.getItem('token');
}

export default service;
